The QuickZip method is nice for simple zipping operations. For more sophisticated manipulation of an archive and its items, the Zip method can be used. Items can be added and removed using the Add and RemoveAt methods. Prior to zipping, individual items' properties, such as Password and Comment, can be set. The zipped archive destination can be a file or stream, according to the application needs.
C# |
Copy Code |
---|---|
//Add a file using the ArchiveItem constructor ArchiveItem item = new ArchiveItem("c:\\Test\\file1.txt"); archive1.Add(item); //Add a file using the filename. This could also be used for adding wildcard collections archive1.Add("c:\\Test\\file2.log"); //Add a wildcard collection of files //In this case, all "txt" files in the directory "c:\Test" are added, except "file1.txt" //Subfolders are not included, but the paths are preserved. archive1.IncludeSubs = true; archive1.ExcludePattern= "file1.txt"; archive1.PreservePath = true; archive1.Add("c:\\Test\\*.txt"); if (archive1.Count > 1) { //Set the comment for the second item (index 1) archive1[1].Comment = "This is the second item in the archive!"; //Remove the first item (index 0) archive1.RemoveAt(0); } archive1.Zip("c:\\test.zip"); |
Visual Basic |
Copy Code |
---|---|
'Add a file using the ArchiveItem constructor Dim item As ArchiveItem = New ArchiveItem("c:\Test\file1.txt") Archive1.Add(item) 'Add a file using the filename. This could also be used for adding wildcard collections Archive1.Add("c:\Test\file2.log") 'Add a wildcard collection of files 'In this case, all "txt" files in the directory "c:\Test" are added, except "file1.txt" 'Subfolders are not included, but the paths are preserved. Archive1.IncludeSubs = True Archive1.ExcludePattern = "file1.txt" Archive1.PreservePath = True Archive1.Add("c:\Test\*.txt") If Archive1.Count > 1 Then 'Set the comment for the second item (index 1) Archive1(1).Comment = "This is the second item in the archive, soon to be first!" 'Remove the first item (index 0) Archive1.RemoveAt(0) End If Archive1.Zip("c:\test.zip") |
C# |
Copy Code |
---|---|
System.IO.MemoryStream stream = new System.IO.MemoryStream(); archive1.Zip(stream); MessageBox.Show("The size of the compressed stream is " + stream.Length.ToString() + " bytes."); |
Visual Basic |
Copy Code |
---|---|
Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream() Archive1.Zip(stream) MessageBox.Show("The size of the compressed stream is " + stream.Length.ToString() + "bytes.") |
C# |
Copy Code |
---|---|
archive1.BeginZip("c:\\test.zip", null); ... private void archive1_EndZip(object sender, Dart.PowerTCP.Zip.EndEventArgs e) { try { if (e.Exception == null) MessageBox.Show("Zip Complete!"); else MessageBox.Show(e.Exception.Message); } catch {} } |
Visual Basic |
Copy Code |
---|---|
Archive1.BeginZip("c:\test.zip", Nothing) ... Private Sub Archive1_EndZip(ByVal sender As Object, ByVal e As Dart.PowerTCP.Zip.EndEventArgs) Handles Archive1.EndZip Try If (e.Exception Is Nothing) Then MessageBox.Show("Zip Complete!") Else MessageBox.Show(e.Exception.Message) End If Catch End Try End Sub |